﻿<UserControl x:Class="ScrumFactory.Backlog.Backlog"             
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"             
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             xmlns:props="clr-namespace:ScrumFactory.Backlog.Properties"
             
             xmlns:SF_Comp="clr-namespace:ScrumFactory.Composition;assembly=ScrumFactory.Composition"                             
             xmlns:SF_CompViewModel="clr-namespace:ScrumFactory.Composition.ViewModel;assembly=ScrumFactory.Composition"
             xmlns:SF="clr-namespace:ScrumFactory;assembly=ScrumFactory"   
             
             xmlns:SF_Helpers="clr-namespace:ScrumFactory.Windows.Helpers;assembly=ScrumFactory.Windows.Helpers"
             
             
             x:Name="backlogView"
             
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <UserControl.InputBindings>
        <KeyBinding Key="Enter" Command="{Binding CreateNewBacklogItemCommand}"/>
    </UserControl.InputBindings>
    
    <UserControl.Resources>
        
        <Style x:Key="StatusFilterImage" TargetType="{x:Type Image}">
            <Setter Property="Width" Value="32"/>
            <Setter Property="Height" Value="32"/>
            <Setter Property="Stretch" Value="Uniform"/>
            <Style.Triggers>
                <DataTrigger Binding="{Binding .}" Value="0">
                    <Setter Property="Source" Value="/Images/ToolBar/todo_backlog.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding .}" Value="1">
                    <Setter Property="Source" Value="/Images/ToolBar/planning_backlog.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding}" Value="2">
                    <Setter Property="Image.Source" Value="/Images/ToolBar/selected_backlog.png"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding}" Value="3">
                    <Setter Property="Image.Source" Value="/Images/ToolBar/all_backlog.png"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
        
        <ObjectDataProvider  x:Key="backlogFilterList" MethodName="GetValues" ObjectType="{x:Type sys:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="SF_CompViewModel:BacklogStatusFilter"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        
        <DataTemplate x:Key="BacklogStatusFilterDataTemplate">
            <StackPanel Orientation="Vertical">
                <Image Style="{StaticResource StatusFilterImage}"/>                
                <TextBlock FontSize="{StaticResource SmallFontSize}"
                           TextTrimming="CharacterEllipsis"
                           HorizontalAlignment="Center"
                           Foreground="{StaticResource ToolBarItemBrush}"
                           Text="{Binding ., Converter={StaticResource LocalizeConverter}, ConverterParameter='ScrumFactory.Backlog.Backlog,ScrumFactory.Backlog'}"/>
            </StackPanel>            
        </DataTemplate>

        <DataTemplate x:Key="BacklogStatusFilterDropDownDataTemplate">
            <StackPanel Orientation="Horizontal">                
                <Image Style="{StaticResource StatusFilterImage}" Margin="0,0,5,0"/>
                <TextBlock>
                    <Run Text="{Binding ., Converter={StaticResource LocalizeConverter}, ConverterParameter='ScrumFactory.Backlog.Backlog,ScrumFactory.Backlog'}"/>    
                    <LineBreak/>
                    <Run FontSize="{StaticResource SmallFontSize}" Foreground="{StaticResource SubTextBrush}"                         
                         Text="{Binding ., Converter={StaticResource LocalizeWithTooltipConverter}, ConverterParameter='ScrumFactory.Backlog.Backlog,ScrumFactory.Backlog'}"/>
                </TextBlock>                
            </StackPanel>
        </DataTemplate>

    </UserControl.Resources>

    <Grid HorizontalAlignment="Stretch">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        
        <Grid Grid.Row="0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
            </Grid.ColumnDefinitions>
            <ToolBar Grid.Column="0">                
                <Border>
                    <StackPanel Orientation="Horizontal">
                        <TextBox x:Name="newItemTextBox"       
                            ToolTip="{x:Static props:Resources.New_item_name}"
                            Width="400"
                            Text="{Binding NewItemName, UpdateSourceTrigger=PropertyChanged}"                                                         
                            HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        <MenuItem Header="{x:Static props:Resources.New_item}" Command="{Binding Path=CreateNewBacklogItemCommand}">
                            <MenuItem.Icon>
                                <Image Source="/Images/ToolBar/Add.png" Width="32" Height="32" Stretch="Uniform"/>
                            </MenuItem.Icon>
                        </MenuItem>
                    </StackPanel>
                </Border>                    
            </ToolBar>
            <ToolBar Grid.Column="1">
                <Border>
                    <StackPanel Orientation="Horizontal">
                        <TextBox 
                             ToolTip="{x:Static props:Resources.Search}"                             
                             Width="120"       
                            Text="{Binding SearchFilterText, UpdateSourceTrigger=PropertyChanged}"
                            Style="{StaticResource SearchTextBox}"
                             HorizontalAlignment="Center" VerticalAlignment="Center"/>
                        <ComboBox x:Name="itemStatusFilterComboBox"                                                                 
                              Width="80" 
                              Style="{StaticResource CleanComboBox}"                                  
                              SelectedItem="{Binding StatusFilter}"
                              VerticalAlignment="Center"                                                                
                              ItemsSource="{Binding Source={StaticResource backlogFilterList}}">                            
                            <ComboBox.ItemTemplate>
                                <DataTemplate>                                    
                                    <ContentControl x:Name="content" Content="{Binding}" ContentTemplate="{StaticResource BacklogStatusFilterDropDownDataTemplate}"/>                                    
                                    <DataTemplate.Triggers>
                                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=ComboBoxItem}}" Value="{x:Null}">
                                            <Setter TargetName="content" Property="ContentTemplate" Value="{StaticResource BacklogStatusFilterDataTemplate}"/>
                                        </DataTrigger>
                                    </DataTemplate.Triggers>
                                </DataTemplate>
                            </ComboBox.ItemTemplate>

                        </ComboBox>
                    </StackPanel>
                </Border>
            </ToolBar>


        </Grid>
        
      
        <ContentControl Grid.Row="1"                        
                        HorizontalAlignment="Center"
                        VerticalAlignment="Center"                          
                        Style="{StaticResource LoadingAnimationContent}"/>

        <ListView
            x:Name="listview"
            Grid.Row="1"            
            SF_Helpers:ListViewColumnsExtension.Stretch="True"
            ItemsSource="{Binding FilteredBacklog}"            
            Margin="0,5,0,0"
            ScrollViewer.VerticalScrollBarVisibility="Auto"
            ScrollViewer.HorizontalScrollBarVisibility="Disabled"
            ItemContainerStyle="{StaticResource NoHoverListViewItem}"
            VerticalAlignment="Stretch"                        
            BorderThickness="0">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="#" Width="40">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <TextBlock Text="{Binding Item.BacklogItemNumber}"                                           
                                           FontSize="{StaticResource BigFontSize}"
                                           FontWeight="Bold"
                                           Foreground="{StaticResource SubTextBrush}" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Status}"  Width="40">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <Image                                    
                                    DataContext="{Binding Item.Status,Converter={StaticResource EnumToShortConverter}, ConverterParameter={x:Type SF:BacklogItemStatus}}" Style="{StaticResource BacklogItemStatusImage}" Width="24" Height="24" Stretch="Uniform" />
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Item}">
                        <GridViewColumn.CellTemplate>                            
                            <DataTemplate>
                                <StackPanel      
                                    HorizontalAlignment="Stretch"
                                    SF_Comp:CommandBehavior.RoutedEventName="MouseLeftButtonDown"
                                    SF_Comp:CommandBehavior.TheCommandToRun="{Binding ShowDetailWindowCommand}"                                    
                                    Cursor="Hand">                                    
                                    <TextBlock FontSize="{StaticResource BigFontSize}" Foreground="{StaticResource LabelBrush}" Text="{Binding Item.Name}" HorizontalAlignment="Stretch"/>
                                    <TextBlock
                                        Foreground="{StaticResource SubTextBrush}"
                                        Text="{Binding Item.Description}"                                        
                                        MaxHeight="100"
                                        TextWrapping="Wrap"  TextTrimming="CharacterEllipsis"/>
                                    <DockPanel x:Name="actionsMenu" Opacity="0" HorizontalAlignment="Stretch">
                                        <TextBlock DockPanel.Dock="Left">
                                            <Hyperlink
                                                Command="{Binding ShowDetailWindowCommand}">
                                                <TextBlock Text="{x:Static props:Resources.View_details}"/>                                                                                   
                                            </Hyperlink>                                                                                        
                                        </TextBlock>
                                        <Button
                                            DockPanel.Dock="Right" HorizontalAlignment="Right"                                            
                                            Style="{StaticResource RemoveButton}"                                             
                                            Command="{Binding ElementName=backlogView, Path=DataContext.DeleteBacklogItemCommand}"
                                            CommandParameter="{Binding}"/>               
                                    </DockPanel>
                                    
                                    
                                    <StackPanel.Triggers>                                        
                                        <EventTrigger RoutedEvent="DockPanel.MouseEnter">                                            
                                            <BeginStoryboard>
                                                <Storyboard>                                                    
                                                    <DoubleAnimation
                                                        Storyboard.TargetName="actionsMenu" 
                                                        Storyboard.TargetProperty="Opacity"
                                                        From="0" To="1" Duration="00:00:01" 
                                                        FillBehavior="HoldEnd" />
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                        <EventTrigger RoutedEvent="DockPanel.MouseLeave">
                                            <BeginStoryboard>
                                                <Storyboard>
                                                    <DoubleAnimation
                                                        Storyboard.TargetName="actionsMenu" 
                                                        Storyboard.TargetProperty="Opacity"
                                                        From="1" To="0" Duration="0" 
                                                        FillBehavior="HoldEnd" />
                                                </Storyboard>
                                            </BeginStoryboard>
                                        </EventTrigger>
                                    </StackPanel.Triggers>
                                </StackPanel>                                
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="{x:Static props:Resources.Hours}" Width="70" >
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical">
                                    <TextBlock TextAlignment="Right">
                                            <Image
                                                HorizontalAlignment="Right"
                                            ToolTip="{x:Static props:Resources.Item_is_late}"
                                            Source="/Images/ErrorStatus/Alert.png" Width="16" Height="16">
                                        <Image.Style>
                                            <Style>
                                                <Style.Triggers>
                                                    <DataTrigger Binding="{Binding CanEditHours}" Value="True">
                                                        <Setter Property="Image.Visibility" Value="Collapsed"/>
                                                    </DataTrigger>
                                                </Style.Triggers>
                                            </Style>
                                        </Image.Style>
                                        </Image>
                                        <TextBlock Text="{Binding Item.CurrentTotalHours, StringFormat='{}0.#'}"                                           
                                           FontSize="{StaticResource ReallyBigFontSize}"
                                           FontWeight="Bold"
                                           HorizontalAlignment="Stretch"
                                           TextAlignment="Right"
                                           Foreground="{StaticResource SubTextBrush}" />
                                    </TextBlock>
                                    
                                    
                                    <TextBlock Foreground="{StaticResource SubTextBrush}"
                                               HorizontalAlignment="Right"
                                               TextAlignment="Right"
                                               TextWrapping="Wrap"
                                               Text="{Binding ItemSprintLabel}"
                                               FontSize="{StaticResource TinyFontSize}"/>    
                                   
                                    
                                    
                                    

                                </StackPanel>
                                
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
            
        
        </ListView>

        <Grid
            Grid.Row="1"
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Image Grid.Column="0" Source="/Images/information.png" Margin="3" VerticalAlignment="Top" Width="16" Height="16" Stretch="Uniform" />
            <TextBlock Grid.Column="1" TextWrapping="Wrap" >
                <TextBlock TextWrapping="Wrap" Text="{x:Static props:Resources.No_items_were_found}"/><LineBreak/>
                <TextBlock TextWrapping="Wrap"                            
                           Margin="0,10,0,0" Foreground="{StaticResource SubTextBrush}" Text="{x:Static props:Resources.No_items_were_found_tip}"/>
            </TextBlock>
            <Grid.Style>
                <Style>
                    <Setter Property="Grid.Visibility" Value="Collapsed"/>
                    <Style.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding ElementName=listview, Path=HasItems}" Value="False"/>
                                <Condition Binding="{Binding IsLoadingData}" Value="False"/>
                            </MultiDataTrigger.Conditions>
                            <Setter Property="Grid.Visibility" Value="Visible"/>
                        </MultiDataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
        </Grid>


    </Grid>
</UserControl>
